package com.guigu.www.erp.tangyingmeng.controller;

import com.guigu.www.erp.common.pojo.DesignModule;
import com.guigu.www.erp.common.pojo.PageVo;
import com.guigu.www.erp.dehao.pojo.User;
import com.guigu.www.erp.tangyingmeng.service.TYMDesignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("TYMDes")
public class TYMDesignController {

    @Autowired
    TYMDesignService service;

     @PostMapping("insert")
    public int wuliaoinsert(@RequestBody DesignModule designModule, HttpSession session){
         User user = (User) session.getAttribute("loginUser");
         int wuliaoinsert = service.wuliaoinsert(designModule, user.getUserName());
         return wuliaoinsert;
     }

     @RequestMapping("selshenhe")
    public PageVo<DesignModule> selshenhe(Integer pageNum,Integer pageSize,HttpSession session){
         User loginUser = (User) session.getAttribute("loginUser");
         if (loginUser.getRole().getRoleId()==4){
             return null;
         }else {
             return service.selshenhe(pageNum, pageSize);
         }
     }

     @PostMapping("selbyoneshenhe/{designModuleId}")
    public DesignModule selbyoneshenhe(@PathVariable("designModuleId")int designModuleId){
         return service.selbyoneshenhe(designModuleId);
     }

     @PutMapping("zhun/{designId}")
    public int zhun(@PathVariable("designId")String designId,HttpSession session){
         User user = (User) session.getAttribute("loginUser");
         int cpshenhe = service.cpshenhe(designId,user.getUserName(),"1");
         return cpshenhe;
     }

    @PutMapping("bu/{designId}")
    public int bu(@PathVariable("designId")String designId,HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        int cpshenhe = service.cpshenhe(designId,user.getUserName(),"2");
        return cpshenhe;
    }

    @RequestMapping("selcx")
    public PageVo<DesignModule> selcx(Integer pageNum,Integer pageSize,String productName){
        PageVo<DesignModule> selcx = service.selcx(pageNum,pageSize,productName);
        return selcx;
    }

    @GetMapping("cxshenhe")
    public Map<String,Integer> cxshenhe(){
        Map<String, Integer> cxshenhe = service.cxshenhe();
        return cxshenhe;
    }

    @PostMapping("cxselbyone/{designModuleId}")
    public DesignModule cxselbyone(@PathVariable("designModuleId") int designModuleId){
        DesignModule module = service.selbyoneshenhe(designModuleId);
        return module;
    }

    @PutMapping("wuliaobg")
    public int wuliaobg(@RequestBody DesignModule designModule, HttpSession session){
        User user = (User) session.getAttribute("loginUser");
        int wuliaobg = service.wuliaobg(designModule, user.getUserName());
        return wuliaobg;
    }

    @RequestMapping("selbg")
    public PageVo<DesignModule> selbg(Integer pageNum,Integer pageSize){
        PageVo<DesignModule> selcx = service.selbg(pageNum,pageSize);
        return selcx;
    }
}
